/* 表单验证 */
import Vue from 'vue'
import VeeValidate, { Validator } from 'vee-validate'
import zh_CN from 'vee-validate/dist/locale/zh_CN'

Vue.use(VeeValidate)

const dictionary = {
  zh_CN: {
    messages: {
      required: (field) => '请输入' + field,
      regex: (field) => '请输入有效的' + field
    },
    attributes: {
      phone: '手机',
      password: '密码',
      code: '验证码',
      name: '姓名',
      newPassword: '新密码',
      newPassword2: '确认密码'
    }
  }
}

Validator.localize('zh_CN', Object.assign(zh_CN, dictionary.zh_CN))

Validator.extend('phone', {
  getMessage: () => '请输入正确的手机号',
  validate: value => {
    return value.length === 11 && /^(1[3456789]\d{9})$/.test(value)
  }
})
